var demo;
var selectData;
$(function() {
    // $('.score').searchableSelect();
    
    if($("#is_add").val()==0){
        // checkRole();
    }    
    
    $('#document-file1').change(function () {
        uploadFile(1);
    });

    $('#document-file2').change(function () {
        uploadFile(2);
    });

    $('#document-file3').change(function () {
        uploadFile(3);
    });

    $(".del-icon").click(function(){
        console.log(11);
        var path = $(this).parent('.data-box').find('.path').val();
        $(this).parent('.data-box').remove();
    })

    saveImg3();//缓存加载保存图片

    $.ajax({
        url: $('input[name="url"]').val()+'Home/Class_Assess/getSelect/'+$('#cc_type').val(),
        type: 'POST',
        dataType: 'json',
        async:false,
        success:function(data){
            if(data.status){
                var t=JSON.parse(data.v);
                selectData=t;
                // console.log(t);

                // 新增身份默认选择第一个
                if($("#is_add").val()==0){
                    if($("#is_mr_ldgb").val() == 1){
                        $.each(t['type'], function(k, v) {
                            if(v == '领导干部'){
                                $("#role").val(t['type'][k]);
                            }
                        });
                    }else{
                        $("#role").val(t['type'][0]);
                    }
                    
                    $("#listen_type").val(t['listen_type'][0]);
                }
            }
        }
    })
// $("input").click(function() {
//     $(this).siblings("div").children("span").addClass("active");
//     $(this).parents("div").siblings("div").find("span").removeClass("active");
//     console.log($("input[name='fruit']").val());
// });
// var class_type = new MobileSelect({
//       trigger: '#class_type_old',
//       title: '请选择课程类型',
//     wheels: [
//                 {data:selectData['class_type_old']}
//       ],
//       position:[0],//初始化定位 打开时默认选中的哪个 如果不填默认为0
//       callback:function(indexArr, data){
//             console.log(data[0]);
//             $("#class_type_old").val(data[0]);
//             $("#class_type_old").blur();
//       }
//     });

    // class_type = new MobileSelect({
    //     trigger: '#class_type',
    //     title: '请选择课程类型',
    //   wheels: [
    //               {data:selectData['class_type']}
    //     ],
    //     position:[0],//初始化定位 打开时默认选中的哪个 如果不填默认为0
    //     callback:function(indexArr, data){
    //           $("#class_type").val(data[0]);
    //           $("#class_type").blur();
    //     }
    //   });

     //获取默认的教师职称
     var teacher_title_arr = selectData['title'];
     var default_teacher_title = 0;
     $.each(teacher_title_arr, function(k, v) {
         if(v == $("#teacher_title").val()){
             default_teacher_title = k;
             console.log(k);       
         }
         
     });

    var teacher_title = new MobileSelect({
      trigger: '#teacher_title',
      title: '请选择职称',
    wheels: [
                {data:selectData['title']}
      ],
      position:[default_teacher_title],//初始化定位 打开时默认选中的哪个 如果不填默认为0
      callback:function(indexArr, data){
            $("#teacher_title").val(data[0]);
            $("#teacher_title").blur();
      }
    });

    // age_groups = new MobileSelect({
    //   trigger: '#age_groups',
    //   title: '请选择年龄层次',
    // wheels: [
    //             {data:selectData['age_groups']}
    //   ],
    //   position:[0],//初始化定位 打开时默认选中的哪个 如果不填默认为0
    //   callback:function(indexArr, data){
    //         $("#age_groups").val(data[0]);
    //         $("#age_groups").blur();
    //   }
    // });

    
    //获取默认的教师属性
    var teachers_attribute_arr = selectData['teachers_attribute'];
    var default_teachers_attribute = 0;
    $.each(teachers_attribute_arr, function(k, v) {
        if(v == $("#teachers_attribute").val()){
            default_teachers_attribute = k;
            console.log(k);       
        }
        
    });
   var teachers_attribute = new MobileSelect({
      trigger: '#teachers_attribute',
      title: '请选择教师属性',
    wheels: [
                {data:selectData['teachers_attribute']}
      ],
      position:[default_teachers_attribute],//初始化定位 打开时默认选中的哪个 如果不填默认为0
      callback:function(indexArr, data){
            $("#teachers_attribute").val(data[0]);
            $("#teachers_attribute").blur();
      }
    });
        new Jdate({
            el: '#listen_time',
            format: 'YYYY-MM-DD hh:mm',
            beginYear: 2000,
            endYear: 2100
          })

    //获取默认的听课身份
    var type_arr = selectData['type'];
    console.log(type_arr)
    console.log($("#role").val())
    var default_type = 0;
    $.each(type_arr, function(k, v) {
        if(v == $("#role").val()){
            default_type = k;
            console.log(k);       
        }
        
    });

    var role = new MobileSelect({
      trigger: '#role',
      title: '请选择听课身份',
    wheels: [
                {data:selectData['type']}
      ],
      position:[default_type],//初始化定位 打开时默认选中的哪个 如果不填默认为0
      callback:function(indexArr, data){
            $("#role").val(data[0]);
            $("#role").blur();
      }
    });


    //获取默认的开课单位
    var course_units_arr = selectData['course_units'];
    var default_course_units = 0;
    $.each(course_units_arr, function(k, v) {
        if(v == $("#course_units").val()){
            default_course_units = k;
            console.log(k);       
        }
         
    });

    course_units = new MobileSelect({
      trigger: '#course_units',
      title: '请选择开课单位',
    wheels: [
            {data:selectData['course_units']}
      ],
      position:[default_course_units],//初始化定位 打开时默认选中的哪个 如果不填默认为0
      callback:function(indexArr, data){
        // console.log(data[4]);
            $("#course_units").val(data[0]);
            $("#course_units").blur();
      }
    });

     //获取默认的听课类型
     var listen_type_arr = selectData['listen_type'];
     var default_listen_type = 0;
     $.each(listen_type_arr, function(k, v) {
         if(v == $("#listen_type").val()){
             default_listen_type = k;
             console.log(k);       
         }
          
     });

    var listen_type = new MobileSelect({
      trigger: '#listen_type',
      title: '请选择听课类型',
    wheels: [
                {data:selectData['listen_type']}
      ],
      position:[default_listen_type],//初始化定位 打开时默认选中的哪个 如果不填默认为0
      callback:function(indexArr, data){
            $("#listen_type").val(data[0]);
            $("#listen_type").blur();
      }
    });
    $("#goto_step2").click(function(event) {  
           //给当前地址添加参数
        var newurl = updateQueryStringParameter(window.location.href, 'next', '2');
        //向当前url添加参数，没有历史记录
        window.history.replaceState({
            path: newurl
        }, '', newurl);
        /*resetFields();
        var emptyfieldsCount=new Array();
        var emptyfields = $("#step1 input[value=]");
        console.log(emptyfields);

        $.each(emptyfields, function(k, v) {
            var val=$(this).val();
            console.log(val);
             if(val=='' || val==null){
                emptyfieldsCount.push(v);
             }
        });
       // emptyfieldsCount.shift();
        if (emptyfieldsCount.length > 0) {
            $.each(emptyfieldsCount, function(index, val) {
                if(index==0){
                window.location.hash = '#'+$(this).attr('id');
                console.log(this);
                console.log('#'+$(this).attr('id'));
            }
                 $(this).stop()
                .animate({ left: "-10px" }, 100).animate({ left: "10px" }, 100)

                .animate({ left: "-10px" }, 100).animate({ left: "10px" }, 100)

                .animate({ left: "0px" }, 100)

                .addClass("required");  
                console.log($(this));
               $(this).focus();
            
            });
            return;
        }   */     
        $("#steps").step("next");         
        $("#step1").hide();
        $("#step2").show();
        console.log('第2页');
        // $("#nextTop").val('2');
        // console.log( $("#nextTop").val());
        // getTop();   
        // $("#steps").step("next");
        // console.log( getTop());
    });           
    $("#goto_step3").click(function(event) {
        //给当前地址添加参数
        var newurl = updateQueryStringParameter(window.location.href, 'next', '3');
        //向当前url添加参数，没有历史记录
        window.history.replaceState({
            path: newurl
        }, '', newurl);

       // window.location.hash = '?next=2';
        var record=$("#recordid3").val();
        var advice=$("#attend5").val();
        

        // console.log(img);
        // 保存听课记录session
        $.post($('input[name="url"]').val() + "Home/Class_Assess/saveText", {record:record,advice:advice}, function(data) {            
       }, "json"); 

       $("#step3").show();
        $("#step2").hide();
        console.log('第3页');
        // $("#nextTop").val('3');
        // console.log( $("#nextTop").val());
        getTop();
        $("#steps").step("next");
       
    });
    $("#goto_step4").click(function(event) {     
           //给当前地址添加参数
           var newurl = updateQueryStringParameter(window.location.href, 'next', '4');
           //向当前url添加参数，没有历史记录
           window.history.replaceState({
               path: newurl
           }, '', newurl);      
        $("#step3").hide();
        $("#step4").show();
        console.log('第4页');
        // $("#nextTop").val('4');
        // console.log( $("#nextTop").val());
        getTop();
        $("#steps").step("next");
    });
    $("#goto_step5").click(function(event) {
        var none=0;
       

        // var teachingReadiness1 = $('input:radio[name="teachingReadiness[0]"]:checked').val();
        // var teachingReadiness2 = $('input:radio[name="teachingReadiness[1]"]:checked').val();
        // var teachingReadiness3 = $('input:radio[name="teachingReadiness[2]"]:checked').val();
        // var teachingReadiness4 = $('input:radio[name="teachingReadiness[3]"]:checked').val();
        // var teachingReadiness5 = $('input:radio[name="teachingReadiness[4]"]:checked').val();
        // var teachingReadiness6 = $('input:radio[name="teachingReadiness[5]"]:checked').val();
        // var teachingReadiness7 = $('input:radio[name="teachingReadiness[6]"]:checked').val();
        // var teachingReadiness8 = $('input:radio[name="teachingReadiness[7]"]:checked').val();
        // var teachingReadiness9 = $('input:radio[name="teachingReadiness[8]"]:checked').val();
        // var teachingReadiness10 = $('input:radio[name="teachingReadiness[9]"]:checked').val();
        // var teachingReadiness11 = $('input:radio[name="teachingReadiness[10]"]:checked').val();
        // var teachingReadiness12 = $('input:radio[name="teachingReadiness[11]"]:checked').val();
        // var teachingReadiness = new Array(teachingReadiness1, teachingReadiness2, teachingReadiness3, teachingReadiness4, teachingReadiness5, teachingReadiness6, teachingReadiness7, teachingReadiness8, teachingReadiness9, teachingReadiness10, teachingReadiness11, teachingReadiness12);
        // var none=0;
        // $.each(teachingReadiness, function(k, v) {
        //     if(typeof v=="undefined"){
        //         $('input[name="teachingReadiness['+k+']"]').parent().css('color', 'red');
        //         $(this).focus();
        //         none++;
        //     }else{
        //         $('input[name="teachingReadiness['+k+']"]').parent().css('color', 'black');
        //     }
        // });     
        if(none==0){
            $("#step4").hide();
            $("#step5").show();
            $("#steps").step("next");
        }
    });
    $("#goto_step6").click(function(event) {           
        $("#step5").hide();
        $("#step6").show();
        getTop();
        $("#steps").step("next");
    });
    /*$("#goto_step5").click(function(event) {


        var classroom_facilities=$('input:radio[name="classroom_facilities"]:checked').val();
        if(typeof classroom_facilities=="undefined"){

            $('input[name="classroom_facilities"]').parent().css('color', 'red');
            return;
        }else{
            $('input[name="classroom_facilities"]').parent().css('color', 'black');
        }
        var classroom_environmental=$('input:radio[name="classroom_environmental"]:checked').val();
        if(typeof classroom_environmental=="undefined"){

            $('input[name="classroom_environmental"]').parent().css('color', 'red');
            return;
        }else{
            $('input[name="classroom_environmental"]').parent().css('color', 'black');
        }          
        
        $("#step5").hide();
        $("#step6").show();
        getTop();
        $("#steps").step("next");
    });*/
     $("#back_step6").click(function(event) {
        $("#step1").hide();
        $("#step6").show();
        getTop();
        $("#steps").step("previous");
    });
    $("#back_step1").click(function(event) {
        //给当前地址添加参数
        var newurl = updateQueryStringParameter(window.location.href, 'next', '1');
        //向当前url添加参数，没有历史记录
        window.history.replaceState({
            path: newurl
        }, '', newurl);    
        $("#step2").hide();
        $("#step1").show();
        console.log('第1页');
        // $("#nextTop").val('1');
        // console.log( $("#nextTop").val());
        getTop();
        $("#steps").step("previous");
    });
    $("#back_step2").click(function(event) {
        //给当前地址添加参数
        var newurl = updateQueryStringParameter(window.location.href, 'next', '2');
        //向当前url添加参数，没有历史记录
        window.history.replaceState({
            path: newurl
        }, '', newurl);    
        $("#step3").hide();
        $("#step2").show();
        console.log('第2页');
        // $("#nextTop").val('2');
        // console.log( $("#nextTop").val());
      
        getTop();
        $("#steps").step("previous");
    });
    $("#back_step3").click(function(event) {
        //给当前地址添加参数
        var newurl = updateQueryStringParameter(window.location.href, 'next', '3');
        //向当前url添加参数，没有历史记录
        window.history.replaceState({
            path: newurl
        }, '', newurl);    
        $("#step4").hide();
        $("#step3").show();
        console.log('第3页');
        // $("#nextTop").val('3');
        // console.log( $("#nextTop").val());
        getTop();
        $("#steps").step("previous");
    });
    $("#back_step4").click(function(event) {
          //给当前地址添加参数
          var newurl = updateQueryStringParameter(window.location.href, 'next', '4');
          //向当前url添加参数，没有历史记录
          window.history.replaceState({
              path: newurl
          }, '', newurl);    
        $("#step5").hide();
        $("#step4").show();
        console.log('第4页');
        // $("#nextTop").val('4');
        // console.log( $("#nextTop").val());
        getTop();
        $("#steps").step("previous");
    });
    $("#back_step5").click(function(event) {
        $("#step6").hide();
        $("#step5").show();
        getTop();
        $("#steps").step("previous");
    });
   
    $(".tag_val").on('change','#studentsNorm1',function(event) {   
        var studentsNorm1=$("#studentsNorm1").val();
        var studentsNorm3=$("#studentsNorm3").val();
        if(studentsNorm1!='' && studentsNorm3!=''){
           var studentsNorm4 = (studentsNorm3/studentsNorm1)*100;
            studentsNorm4.toFixed(2);
            studentsNorm4=studentsNorm4;
            $("#studentsNorm4").val(studentsNorm4);
            console.log($("#studentsNorm4").val());            
        }
    });
    $(".tag_val").on('change','#studentsNorm3',function(event) {   
        var studentsNorm1=$("#studentsNorm1").val();
        var studentsNorm3=$("#studentsNorm3").val();
        if(studentsNorm1!='' && studentsNorm3!=''){
           var studentsNorm4 = (studentsNorm3/studentsNorm1)*100;
            studentsNorm4.toFixed(2);
            studentsNorm4=studentsNorm4;
            $("#studentsNorm4").val(studentsNorm4);
            console.log($("#studentsNorm4").val());
        }
    });
     
    if($("#is_add").val()==0){
        var recordcount = 1;
        $("#step6").on('click', '#add_record', function(event) {
            recordcount++;
            $(".content").append("<div><div class='div_border row'><div class='col-xs-2 tag_name ''>时间</div><div class='col-xs-9 tag_val'><input type='text' readOnly class='form-control time_HMS add write'></div></div><div class='div_border' style='height: auto!important;'><div class='div_border row'><div class='col-xs-3 tag_name  ' >教学活动</div><div class='col-xs-9 tag_val '><input type='text' placeholder='请输入教学活动' class='form-control add write' ></div></div><div class='div_border row'><div class='col-xs-3 tag_name  ' >随堂评注</div><div class='col-xs-9 tag_val '><input type='text' placeholder='请输入随堂评注' class='form-control add write' ></div></div></div>");
            var recordid = 3;//原来
            var mydate = new Date();
            var t = mydate.toLocaleString();
            var hour = mydate.getHours();
            var minutes = mydate.getMinutes();
            var second = mydate.getSeconds();
            $(".time_HMS:last").val(hour + ":" + minutes + ":" + second);
            $("#step6_form .add").each(function() {
                // $(this).last().attr("id", "attend_record" + recordid);
                $(this).last().attr("name", "attend_record[" + recordid+"]");
                recordid = recordid + 1;
            });
            
            $("#recordcount").val(recordcount);
        });
        var mydate = new Date();
        var t = mydate.toLocaleString();
        var hour = mydate.getHours();
        var minutes = mydate.getMinutes();
        var second = mydate.getSeconds();
        var myYear = mydate.getFullYear();  // 获取当前年份
        var myMonth = mydate.getMonth() +1; // 获取当前月份
        var myDay = mydate.getDate() // 获取当前日（1- 31）
        $(".time_HMS").val(myYear+'-'+myMonth+'-'+myDay+' '+hour + ":" + minutes + ":" + second);
    }else{
        var recordcount=$(".content").length;
    }
    
    var $tgaUpload = $('#Upload').diyUpload({
        url: 'upload/image',
        success: function(data) {},
        error: function(err) {},
        buttonText: '',
        accept: {
            title: "Images",
            extensions: 'gif,jpg,jpeg,bmp,png'
        },
        thumb: {
            width: 800,
            height: 600,
            quality: 100,
            allowMagnify: true,
            crop: true,
            type: "image/jpeg"
        }
    });


    $("#submit").click(function(event) {
        // var classroom_facilities=$('input:radio[name="classroom_facilities"]:checked').val();
        // if(typeof classroom_facilities=="undefined"){

        //     $('input[name="classroom_facilities"]').parent().css('color', 'red');
        //     return;
        // }else{
        //     $('input[name="classroom_facilities"]').parent().css('color', 'black');
        // }
        // var classroom_environmental=$('input:radio[name="classroom_environmental"]:checked').val();
        // if(typeof classroom_environmental=="undefined"){

        //     $('input[name="classroom_environmental"]').parent().css('color', 'red');
        //     return;
        // }else{
        //     $('input[name="classroom_environmental"]').parent().css('color', 'black');
        // }
        dialog1 = jqueryAlert({
            'style': 'wap',
            'title': '确认是否提交',
            'content':'提交后无法修改',
            'modal': true,
            'contentTextAlign': 'center',
            'width': '300',
            'height': '150',
            'animateType': 'linear',
            'buttons': {
                '取消':function(){
                   dialog1.close();
               },
                '确定':function(){ 
                    save(2);
                   dialog1.close();
               }
           }
       })      
        
    })
    $("#save").click(function(event) {
       /*  var classroom_facilities=$('input:radio[name="classroom_facilities"]:checked').val();
        if(typeof classroom_facilities=="undefined"){

            $('input[name="classroom_facilities"]').parent().css('color', 'red');
            return;
        }else{
            $('input[name="classroom_facilities"]').parent().css('color', 'black');
        }
        var classroom_environmental=$('input:radio[name="classroom_environmental"]:checked').val();
        if(typeof classroom_environmental=="undefined"){

            $('input[name="classroom_environmental"]').parent().css('color', 'red');
            return;
        }else{
            $('input[name="classroom_environmental"]').parent().css('color', 'black');
        } */
        save(1);
        
    })
});

function resetFields() {

$("input[type=text]").removeClass("required");

}

function checkRadio(radioName){
return $("input[name="+radioName+"]:checked").val() == null ? false : true;
}

function getTop() {
    $("body,html").animate({
        scrollTop: 0
    },100);
}

function score(t){
    $(".score_demo").html('');
    score = new selectSwiper({
        el: '.score_demo',
        mustSelect:true, // 是否必选，默认false
        data: selectData['age_groups'],
        init:function(index){},
        okFunUndefind: function() { //选择空执行
            errorAlert('请选择');
            return false;
        },
        okFun: function(index) { //确认按钮执行
            type=this.data[index];
            $(t).html(type);
            
        }
    });   
    score.openSelectSwiper();
}

function save(status){
    var attend1 = $("#attend1").val();
        var attend2 = $("#attend2").val();
        var attend3 = $("#attend3").val();
        var attend4 = $("#attend4").val();
        var attend5 = $("#attend5").val();
        // var attend6 = $("#attend6").val();
        // var attend7 = $("#attend7").val();
        // var attend8 = $("#attend8").val();
        // var attend9 = $("#attend9").val();
        // var attend10 = $("#attend10").val();
        // var attend11 = $("#attend11").val();
        // var attend12 = $("#attend12").val();
        // var attend = new Array(attend1, attend2, attend3, attend4, attend5, attend6, attend7, attend8, attend9, attend10, attend11, attend12);
        var class_id =$("#class_id").val();
        var teacher_id =$("#teacher_id").val();
        // console.log($("#class_id"));
        // console.log($("#teacher_id"));
        // return;
        var attend= new Array(class_id,teacher_id,attend1,attend2,attend3,attend4,attend5);
        var teachingLevel1= $('#teachingLevel1').val();
        var teachingLevel2 = $("#teachingLevel2").val();
        var teachingLevel3 = $("#teachingLevel3").val();
        var teachingLevel4 = $("#teachingLevel4").val();
        var teachingLevel5 = $("#teachingLevel5").val();
        var teachingLevel6 = $("#teachingLevel6").val();
        var teachingLevel7 = $("#teachingLevel7").val();
        var teachingLevel8 = $("#teachingLevel8").val();
        var teachingLevel9 = $("#teachingLevel9").val();
        var teachingLevel = new Array(teachingLevel1, teachingLevel2, teachingLevel3, teachingLevel4, teachingLevel5, teachingLevel6, teachingLevel7, teachingLevel8, teachingLevel9);
        var teachingEffect1 = $("#teachingEffect1").val();
        var teachingEffect2 = $("#teachingEffect2").val();
        var teachingEffect3 = $("#teachingEffect3").val();
        var teachingEffect4 = $("#teachingEffect4").val();
        var teachingEffect5 = $("#teachingEffect5").val();
        var teachingEffect6 = $("#teachingEffect6").val();
        var teachingEffect = new Array(teachingEffect1, teachingEffect2, teachingEffect3, teachingEffect4, teachingEffect5, teachingEffect6);
        var teachingReadiness1 = $('input:radio[name="item1"]:checked').val();
        var teachingReadiness2 = $('input:radio[name="item2"]:checked').val();
        var teachingReadiness3 = $('input:radio[name="item3"]:checked').val();
        var teachingReadiness4 = $('input:radio[name="item4"]:checked').val();
        var teachingReadiness5 = $('input:radio[name="item5"]:checked').val();
        var teachingReadiness6 = $('input:radio[name="item6"]:checked').val();
        var teachingReadiness7 = $('input:radio[name="item7"]:checked').val();
        var teachingReadiness8 = $('input:radio[name="item8"]:checked').val();
        var teachingReadiness9 = $('input:radio[name="item9"]:checked').val();
        var teachingReadiness10 = $('input:radio[name="item10"]:checked').val();
        var teachingReadiness11 = $('input:radio[name="item11"]:checked').val();
        var teachingReadiness12 = $('input:radio[name="item12"]:checked').val();
        var teachingReadiness = new Array(teachingReadiness1, teachingReadiness2, teachingReadiness3, teachingReadiness4, teachingReadiness5, teachingReadiness6, teachingReadiness7, teachingReadiness8, teachingReadiness9, teachingReadiness10, teachingReadiness11, teachingReadiness12);
        var studentsNorm1 = $("#studentsNorm1").val();
        var studentsNorm2 = $("#studentsNorm2").val();
        var studentsNorm3 = $("#studentsNorm3").val();
        var studentsNorm4 = (studentsNorm3/studentsNorm1)*100;
        studentsNorm4.toFixed(2);
        studentsNorm4=studentsNorm4+'%';
        $("#studentsNorm4").val(studentsNorm4);        
        var studentsNorm5 = $("#studentsNorm5").val();
        var studentsNorm6 = $("#studentsNorm6").val();
        var studentsNorm7 = $("#studentsNorm7").val();
        var studentsNorm8 = $("#studentsNorm8").val();
        var studentsNorm9 = $("#studentsNorm9").val();
        var studentsNorm = new Array(studentsNorm1, studentsNorm2, studentsNorm3, studentsNorm4, studentsNorm5, studentsNorm6, studentsNorm7, studentsNorm8, studentsNorm9);
        var classroom_facilities = $('input:radio[name="item13"]:checked').val();
        var classroom_environmental = $('input:radio[name="item14"]:checked').val();
        var attend_record = new Array();
        $("#step6_form .write").each(function() {
            attend_record.push($(this).val());
        });
        $("#attend_record").val(attend_record);
        var is_add=$("#is_add").val();

        

        var k=0;
        $("#img").html('');
        $("li img").each(function(k,v) {
            console.log(this);
            $("#img").append("<input type='hidden' name='attend_img["+k+"]' class='attend_img' value='"+$(this).attr('src')+"'>");
            k++;
        });
        
        var attend_id=$('#is_add').val()
        if(attend_id==0){
            var url='Home/Class_Assess/saveAttend';
        }else{
           var url='Home/Class_Assess/saveAttend/'+attend_id;
       }
       console.log($("#img .attend_img").val());
       var data=$("form").serialize();
       data=data+"&save="+status;

    //    $("#submit").attr('disabled',true);
    //    $("#save").attr('disabled',true);
    $.ajax({
        url: $('input[name="url"]').val() + url,
        type: 'POST',
        dataType: 'json',
      
        data:data,
        success: function(data) {
            var t=JSON.parse(data.v);
            if (data.status) {
                var dialog1 = jqueryAlert({
                    'icon': $('input[name="url"]').val() + 'public/home/alert/img/right.png',
                    'content': data.msg,
                    'closeTime': 10000,
                })
                // setTimeout(window.location.href = $('input[name="url"]').val()+"Home/Index",1000);
                if(status == 1){
                    const httpurl = window.location.href.split('Index/')[0];
                    const httpend = window.location.href.split('Index/')[1];
                    const url3 = httpend.split('/');
                    const url4 = url3[2].split('?');
                    if(url4[0] == '0'){
                        // const newurl = httpurl+'Index/'+url3[0]+'/'+url3[1]+'/'+t+'?'+url4[1];
                        setTimeout(window.location.href = httpurl+"Index/2/"+url3[1]+"/"+t+"?"+url4[1],1000);
                    }else{
                        setTimeout(window.location.href = "",1000);
                    }
                  
                    // console.log(httpurl);
                    // console.log(httpend);
                    // console.log(url3);
                    // console.log(newurl);
                    
                    // setTimeout(window.location.href = $('input[name="url"]').val()+"Home/Class_Assess/SaveAssess",1000);
                }else{
                    setTimeout(window.location.href = $('input[name="url"]').val()+"Home/Class_Assess/SubmittedAssess",1000);
                }
                
            } else {                
                $("#submit").attr('disabled',false);
               $("#save").attr('disabled',false);
                var dialog1 = jqueryAlert({
                    'icon': $('input[name="url"]').val() + 'public/home/alert/img/error.png',
                    'content': data.msg,
                    'closeTime': 1000,
                })
                if(t['error']==1){
                    for(var i=1;i<=6;i++){
                        $("#step"+i).hide();
                    }
                    $("#steps").step("goto", 3);
                    $("#step3").show();
                }else if(t['error']==2){
                    for(var i=1;i<=6;i++){
                        $("#step"+i).hide();
                    }
                    $("#steps").step("goto", 4);
                    $("#step4").show();
                }else if(t['error']==3){
                   $(".alert-container").css('display','block');
                   $(".alert-modal").css('display','block');
                }
            }
        }
    })
}


function checkRole(){
    $.ajax({
            url: $('input[name="url"]').val()+'Home/Class_Assess/checkSubrole',
            type: 'POST',
            dataType: 'json',
            async:false,
            success:function(data){
                if(data.status){
                    var t=JSON.parse(data.v);
                    if(t['html']){
                        dialog1 = jqueryAlert({
                            'style': 'wap',
                            'title': '请选择提交反馈身份',
                            'content': t['html'],
                            'modal': true,
                            'contentTextAlign': 'center',
                            'width': '300',
                            'height': '120',
                            'animateType': 'linear',
                            'buttons': {
                               
                                '确定':function(){
                                   if($("#sub_role").val()=='0'){
                                        var dialog2 = jqueryAlert({
                                        'icon': $('input[name="url"]').val() + 'public/home/alert/img/error.png',
                                        'content': '请选择反馈身份！',
                                        'closeTime': 1000,
                                    })
                                   }else{
                                        dialog1.close();
                                        $('input[name="sub_role"]').val($("#sub_role").val());
                                   }
                                   
                               }
                           }
                       })
                    }
                }
            }
        })
}

// 实时计算打分情况
function levelsum(){
    var sum=0;
    $.each($("#step3 input[type='text']"), function(k, v) {
        // console.log(v);
        var id=this.id;
        var val=$('#'+id).val();
        if(val!='' ){
            val=parseInt(val);
            sum+=val;
        }            
    });
    $(".teaching_level_sum").html('当前总分为：<span class="teaching_level_sum1">'+sum+'</span>');
    TotalScore();
}
function effectsum(){
    var sum=0;
    $.each($("#step4 input[type='text']"), function(k, v) {
        var id=this.id;
        var val=$('#'+id).val();
        if(val!='' ){
            val=parseInt(val);
            sum+=val;
        }            
    });
    $(".teaching_effect_sum").html('当前总分为：<span class="teaching_effect_sum1">'+sum+'</span>');
    TotalScore();
}

//计算总评分
function TotalScore(){
    var teaching_level_sum = $(".teaching_level_sum1").text();
    if(teaching_level_sum == ''){
      var teaching_level_sum = 0;
    }

   var teaching_effect_sum = $(".teaching_effect_sum1").text();
    if(teaching_effect_sum == ''){
      var teaching_effect_sum = 0;
    }

    console.log(teaching_level_sum);
    console.log(teaching_effect_sum);
    
    // var sumScore = teaching_level_sum * 0.7 + teaching_effect_sum * 0.3;

    var sumScore = parseInt(teaching_level_sum)  + parseInt(teaching_effect_sum) ;
    // console.log(sumScore);
    if(teaching_effect_sum != '' || teaching_level_sum != '' ){
        console.log(123455);
        $(".score").html('当前总评分为：<span class="score1">' + sumScore+'</span>');
    }

    // if(teaching_level_sum != '' && teaching_effect_sum != ''){
    //     console.log(123455);
    //     $(".score").html('当前总评分为：<span class="score1">' + sumScore+'</span>');
    // }
    

}

// 输入上课班级查询指定课程数据
function checkClass(){
    var teacher_id=$("#teacher_id").val();
    // 上课班级
    var classname=$("#attend4").val();
    // 课程名称
    var name=$("#class_name").val();
    $.ajax({
        url: $('input[name="url"]').val()+'Home/Class_Assess/checkClass',
        type: 'POST',
        dataType: 'json',
        data: {
            teacher_id: teacher_id,
            classname:classname,
            name:name
        },
        success:function(data){
            var t=JSON.parse(data.v);
            if(data.status){
                $("input[name='class_type']").val(t.type);
                $("#class_type").html(t.type);
                $("input[name='course_units']").val(t.course_units);
                $("input[name='class_id']").val(t.id);
            }else{
                $("input[name='class_id']").val('0');
            }
        }
    })
}

// 获取教师信息
function getTeacherInfo(){
    var teacher_code=$("#teacher_name").val();
    $.ajax({
        url: $('input[name="url"]').val()+'Home/Class_Assess/getTeacherInfo',
        type: 'POST',
        dataType: 'json',
        data: {
            teacher_code: teacher_code
        },
        success:function(data){
            var t=JSON.parse(data.v);
            if(data.status){
                console.log(t);
                // $("")
            }else{
                $("input[name='class_id']").val('0');
            }
        }
    })
}

function gotoSearch(){
    window.location.href = $('input[name="url"]').val()+"Home/Search/teatcherIndex/"+$("#is_add").val();
}

function gotoSearch1(){
    // var teacher_code=$("#teacher_code").val();
    //console.log($("#course_units").val(),999);
    var string =  $("#course_units").val().split("（")[0]
	var new_str = "";
	var course_units = "";
    if(string.indexOf("公共") != -1){
        new_str = string.split("公共")[1];
        course_units=encodeURIComponent(new_str);
    }else{
        course_units=encodeURIComponent(string);
    }
	if(string == '马克思主义学院') {
        course_units = 'mkszy';
    } else if(string == '黄酒学院、纺织工程学院') {
        course_units = 'hjxy';
    }
	
    //console.log(new_str,999);
    //console.log(course_units,999); 
    // return;
    // var course_units=encodeURIComponent("设计与艺术学院（腾讯云国际互联网学院）");
     var listen_time=encodeURIComponent($("#listen_time").val());
    if(course_units != '' && listen_time != '' ){
         window.location.href = $('input[name="url"]').val()+"Home/Search/classIndex/"+$("#is_add").val()+'/'+course_units+'/'+listen_time;
    }else if(course_units == '' && listen_time != '' ){
         window.location.href = $('input[name="url"]').val()+"Home/Search/classIndex/"+$("#is_add").val()+'/0/'+listen_time;
    }else if(course_units != '' && listen_time == '' ){
		console.log($('input[name="url"]').val()+"Home/Search/classIndex/"+$("#is_add").val()+'/'+course_units,999)
         window.location.href = $('input[name="url"]').val()+"Home/Search/classIndex/"+$("#is_add").val()+'/'+course_units;
    }else{
         window.location.href = $('input[name="url"]').val()+"Home/Search/classIndex/"+$("#is_add").val();
    }
   
    // window.location.href = $('input[name="url"]').val()+"Home/Search/classIndex/"+$("#is_add").val()+'/'+course_units+'/'+listen_time;
}


var now_type = '';

function uploadDocument(obj,type) {
    now_type = $(obj).attr('data-type');
    $('#document-file'+type).click();
}

function uploadFile(type) {

    var fileObj = document.getElementById("document-file"+type).files; // js 获取文件对象
    if (fileObj.length == 0) {
        errorAlert('请选择图片');
        return;
    }
    var formFile = new FormData();
    for (var i = 0; i < fileObj.length; i++) {
        formFile.append("myfile[]", fileObj[i]); //加入文件对象
    }
    $('.attend_type'+type+' .document-p .progress-bar').css('width', '0%');
    $('.attend_type'+type+' .document-p .p-text').html('已上传（0%）');
    $('.attend_type'+type+' .document-p').show();
    var data = formFile;
    setTimeout(function () {
        $.ajax({
            url: $('input[name="url"]').val() +'/Admin/CommonUpload/upload/' + now_type,
            data: data,
            type: "POST",
            dataType: "json",
            cache: false, //上传文件无需缓存
            processData: false, //用于对data参数进行序列化处理 这里必须false
            contentType: false, //必须
            xhr: xhrOnProgress(function (e) {
                var percent = e.loaded / e.total;
                var now_jindu = (parseFloat(percent) * 100).toFixed(2);
                console.log(now_jindu);
                $('.attend_type'+type+' .document-p .progress-bar').css('width', now_jindu + '%');
                $('.attend_type'+type+' .document-p .p-text').html('已上传（' + now_jindu + '%）');
                $('.attend_type'+type+' .document-p').show();
            }),
            success: function (data) {
                $('.attend_type'+type+' .document-p .progress-bar').css('width', '100%');
                $('.attend_type'+type+' .document-p .p-text').html('已上传（100%）');
                $('.attend_type'+type+' .document-p').hide();
                if (data.status) {
                    // alert(now_type);
                    var path = JSON.parse(data.v);
                    var icon = JSON.parse(data.remark);       
                    $.each(path, function (k, v) {
                        $('.data-box-demo'+type+' img').attr('src',$('input[name="url"]').val() + '/' + v);
                        $('.data-box-demo'+type+' img').attr('data_src',v);
                        $('.data-box-demo'+type+' a').attr('href',$('input[name="url"]').val() + '/' + v);
                        $('.data-box-demo'+type+' .path').val(v).attr('name', 'attend_img_arr'+type+'[]');
                        //  $('.data-box-demo img').attr('src',$('input[name="url"]').val() + '/' + v);
                        //  $('.data-box-demo a').attr('href',$('input[name="url"]').val() + '/' +v);
                        // $('.data-box-demo .path').val(getRootPath() + '/' +v).attr('name', 'attend_img[' + now_type + '][]');
                        //  $('.data-box-demo .icon').val(icon[k]).attr('name', 'icon[' + now_type + '][]');
                        $('.clearfix .td_' + now_type+'_'+type).append($('.data-box-demo'+type).html());
                    });
                    saveImg3();
                } else {
                    // window.parent.topMessagePrompt('error', data.msg);
                    errorAlert(data.msg);
                }
            }
        })
    }, 1000);
}

function delicon(obj){
    var path = $(obj).parent('.data-box').find('.path').val();
    $(obj).parent('.data-box').remove();
}

var xhrOnProgress = function (fun) {
    xhrOnProgress.onprogress = fun; //绑定监听
    //使用闭包实现监听绑
    return function () {
        //通过$.ajaxSettings.xhr();获得XMLHttpRequest对象
        var xhr = $.ajaxSettings.xhr();
        //判断监听函数是否为函数
        if (typeof xhrOnProgress.onprogress !== 'function')
            return xhr;
        //如果有监听函数并且xhr对象支持绑定时就把监听函数绑定上去
        if (xhrOnProgress.onprogress && xhr.upload) {
            xhr.upload.onprogress = xhrOnProgress.onprogress;
        }
        return xhr;
    }
}

//保存学生常态照片
function saveImg3(){
    var img1=[];
    $.each($(".attend_type1 .data-box-banner img"), function(k, v) {
         img1.push($(v).attr('data_src'));
    });
    var img2=[];
    $.each($(".attend_type2 .data-box-banner img"), function(k, v) {
         img2.push($(v).attr('data_src'));
    });
   var img3=[];
    $.each($(".attend_type3 .data-box-banner img"), function(k, v) {
         img3.push($(v).attr('data_src'));
    });

    // 保存听课记录session
    $.post($('input[name="url"]').val() + "Home/Class_Assess/saveText1", {img1:img1,img2:img2,img3:img3}, function(data) {            
   }, "json"); 
}

// 大图预览
function showImage(obj) {
    var img = {
        data: []
    }
    $(obj).parent().parent().parent().find('.path').each(function () {
        // alert($(this).next().val());
        if ($(this).next().val() == 'img.png') {
            img.data.push({
                'alt': '',
                'pid': (Number($(this).index()) + 1),
                'src': $(this).val(),
                'thumb': ''
            });
        }
    });
    if (img.data.length == 0) {
        window.parent.topMessagePrompt('error', '无图片');
    } else {
        showDialogModalPhoto(img);
    }
}


function updateQueryStringParameter(uri, key, value) {
    if(!value) {
        return uri;
    }
    var re = new RegExp("([?&])" + key + "=.*?(&|$)", "i");
    var separator = uri.indexOf('?') !== -1 ? "&" : "?";
    if (uri.match(re)) {
        return uri.replace(re, '$1' + key + "=" + value + '$2');
    }
    else {
        return uri + separator + key + "=" + value;
    }
}

function changeSorce(obj){
    var name=$(obj).attr('data-name')
    var score=$(obj).attr('data-data')    
    var title=$(obj).attr('data-title')    
    console.log(name);
    console.log(score);
    console.log(title);
    score=score.split(',')
    var scoreList=[]
    $.each(score, function (k, v) { 
        scoreList.push(v)
    });
    eval(name).updateWheel(0,scoreList);
    eval(name).locatePosition(0,0)
    $("#"+name).val('')
    $("#"+name).show()
    $(obj).parent().children().last().html(title)
    console.log(111);
    TotalScore();
}
